import 'package:flutter/material.dart';

class StackAndPositionedRoute extends StatelessWidget {
  const StackAndPositionedRoute({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('层叠布局 Stack、Positioned'),
      ),
      body: ConstrainedBox(
        constraints: const BoxConstraints.expand(),
        child: Stack(
          alignment: Alignment.center,
          fit: StackFit.expand, //未定位widget占满Stack整个空间
          children: [
            Container(
              child: const Text(
                "Hello World",
                style: TextStyle(color: Colors.white),
              ),
              color: Colors.red,
            ),
            const Positioned(
              child: Text("I am Jack"),
              left: 18,
            ),
            const Positioned(
              child: Text("Your friend"),
              top: 18,
            ),
          ],
        ),
      ),
    );
  }
}
